<?php
if( !defined( 'HIGHLIGHT_LINK' ) ) {
	define( 'HIGHLIGHT_LINK', 'tags' );
}

class hdms_tagAdminController extends FoundryControllerInterface
{


	/**
	 * init()
	 *
	 * init() is called in place of the __construct() method used by the
	 * FoundryControllerInterface super class
	 * This function will be called immediately after the __construct method
	 *
	 */ 
	public function init()
	{
	
	
	}
	
	public function main()
	{
	
		return true;
	}
	
	public function newTag()
	{
		$name = FoundryRequest::post( 'tagName', 'alnum' );
		
		if( $name ) {
			$tag = $this->tag();
			$tag->name = $name;
			
			$tag->save();
		}
		
		header( "Location: ".
			FoundryView::helperLinkTo( 'tagAdmin/' ) );
		exit;
	}
	
	public function editTag()
	{
		$name = FoundryRequest::post( 'tagName', 'alnum' );
		$id = FoundryRequest::post( 'tagID', 'num' );
		
		if( $name && $id ) {
			$tag = $this->tag( $id );
			$tag->name = $name;
			
			$tag->save();
			
			return $tag;
		}

		return $this->tag();	
	}
	
	public function deleteTag()
	{
		$id = FoundryRequest::post( 'id', 'num' );
		
		if( $id ) {
			$tag = $this->tag( $id );
			
			if( $tag->uid ) {
				$tag->delete();
				
				return $tag;
			}
		}
		
		return $this->tag();
	}

}

?>